package com.example.activitytest1;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (requestCode) {
            case 1:
                if (resultCode == RESULT_OK) {
                    String returnedData = data.getStringExtra("data_return");
                    Log.d("MainActivity", returnedData);
                }
                break;
            default:
        }

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Button button1=(Button)findViewById(R.id.button_1);

        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
               // Intent intent=new Intent(MainActivity.this,SecondActivity.class);//显式
                //Intent intent=new Intent("com.example.activitytest1.ACTION_START");//隐式
                //intent.addCategory("com.example.activitytest1.MY_CATEGORY");
                //Intent intent=new Intent(Intent.ACTION_VIEW);
                //intent.setData(Uri.parse("http://www.baidu.com"));
               // Intent intent = new Intent(Intent.ACTION_SENDTO);
               // intent.setData(Uri.parse("smsto:10086"));
                //intent.putExtra("sms_body","给10086发短信");
                String data="Hello SecondActivity";
                Intent intent=new Intent(MainActivity.this,SecondActivity.class) ;
               // intent.putExtra("extra_data",data);
               // startActivity(intent);
                startActivityForResult(intent,1);
            }
        });

    }
}